package com.ss.android.article.base.feature.feed.vh;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.bytedance.common.utility.UIUtils;
import com.ss.android.action.ArticleActionHelper;
import com.ss.android.article.base.feature.c.FeedItemBehavior;
import com.ss.android.article.base.feature.feed.activity.InfoLayout;
import com.ss.android.article.base.feature.model.FeedCallAppAd;
import com.ss.android.common.ad.MobAdClickCombiner;
import com.ss.android.common.util.NetworkStatusMonitor;
import com.ss.android.common.util.ToolUtils;
import com.ss.android.newmedia.a.TimeFormatter;

import org.json.JSONObject;

import java.util.concurrent.atomic.AtomicBoolean;

public final class a extends af {
    public FeedCallAppAd o;
    private View.OnClickListener p;

    public a(final Context context,
             NetworkStatusMonitor networkStatusMonitor,
             FeedItemBehavior feedItemBehavior,
             ArticleActionHelper articleActionHelper,
             int feedType,
             TimeFormatter timeFormatter,
             int actualImageWidth,
             int actualImageHeight,
             int arg10,
             int arg11,
             int arg12,
             AtomicBoolean arg13) {
        super(context, networkStatusMonitor, feedItemBehavior, articleActionHelper, feedType, timeFormatter, actualImageWidth, actualImageHeight, arg10, arg11, arg12, arg13);
        this.p = new View.OnClickListener() {


            public final void onClick(View view) {
                if (o != null && context != null) {
                    JSONObject jsonObject = new JSONObject();
                    try {
                        if (!android.support.design.a.isTextEmpty(o.logExtra)) {
                            jsonObject.put("log_extra", o.logExtra);
                        }
                        MobAdClickCombiner.onAdEvent(context, "embeded_ad", "click", o.id, 2, jsonObject, 2);
                    } catch (Exception exception) {
                    }

                    if (o.actionType != 1) {
                        return;
                    }

                    if (!android.support.design.a.isTextEmpty(o.phoneNumber)) {
                        try {
                            MobAdClickCombiner.onAdEvent(context, "feed_call", "click_call", o.id, ((long) o.actionType), jsonObject, 2);
                            ToolUtils.e(context, o.phoneNumber);
                        } catch (Exception v0) {
                        }
                    }
                }
            }
        };
    }

    public final void a(View view) {
        if (this.mFeedItemBehavior != null) {
            this.mFeedItemBehavior.handleItemClick(this.mPosition, view, new Object[0]);
        }
    }

    protected final void a_(InfoLayout.Info info) {
        if (this.o != null && (this.mCellRef.n())) {
            String v0 = this.o.appAdSource;
            if (!android.support.design.a.isTextEmpty(v0) && !android.support.design.a.isTextEmpty(v0.trim())) {
                if (this.p()) {
                    if (this.mCellRef.o()) {
                        info.a |= 128;
                    }
                    info.a |= 256;
                }
                if (b(this.o.h, this.mCellRef.subTitle)) {
                    info.a |= 256;
                }
                info.a |= 1;
                info.d = v0;
            }
        }
    }

    protected final void g() {
        InfoLayout v0;
        int v5 = com.ss.android.article.browser.R.dimen.list_item_horizontal_outside_padding;
        int v3 = com.ss.android.article.browser.R.dimen.feed_item_horizontal_margin;
        int v4 = com.ss.android.article.browser.R.dimen.e_;
        int v8 = View.GONE;
        super.g();
        if (this.mCellRef != null) {
            this.o = this.mCellRef.feedCallAppAd;
            if (this.o != null) {
                switch (this.o.h) {
                    case 1: {
                        this.initRightImageAdLayout();
                        break;
                    }
                    case 2: {
                        this.initLargeImageAdInfoLayout();
                        break;
                    }
                    case 3: {
                        this.initMultiImageAdLayout();
                        break;
                    }
                    case 4: {
                        this.initRightImageAdImageLayout();
                        break;
                    }
                }

                this.t();
                this.a(this.o.imageInfo);
                this.d(this.o.h);
                this.g(this.o.h);
                this.c(this.o.h);
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -2);
                switch (this.m()) {
                    case 1:
                    case 2: {
                        v0 = this.mImage3InfoLayout;
                        if (!this.mAppData.getAppSettings().isFeedCellSpacingChange()) {
                            layoutParams.setMargins(this.context.getResources().getDimensionPixelOffset(v3), this.context.getResources().getDimensionPixelOffset(v4),
                                    this.context.getResources().getDimensionPixelOffset(v5), this.context.getResources().getDimensionPixelOffset(com.ss.android.article.browser.R.dimen.feed_info_layout_margin_bottom));
                        } else if (this.mAppData.getAppSettings().isMaxCellSpacingChange()) {
                            layoutParams.setMargins(this.context.getResources().getDimensionPixelOffset(v3), this.context.getResources().getDimensionPixelOffset(v4),
                                    this.context.getResources().getDimensionPixelOffset(v5), ((int) UIUtils.dp2px(this.context, 6f)));
                        } else {
                            layoutParams.setMargins(this.context.getResources().getDimensionPixelOffset(v3), this.context.getResources().getDimensionPixelOffset(v4),
                                    this.context.getResources().getDimensionPixelOffset(v5), ((int) UIUtils.dp2px(this.context, 7f)));
                        }

                        v0.setLayoutParams(layoutParams);
                        break;
                    }
                    case 3: {
                        v0 = this.mImage3InfoLayout;
                        layoutParams.setMargins(this.context.getResources().getDimensionPixelOffset(v3), this.context.getResources().getDimensionPixelOffset(v4),
                                this.context.getResources().getDimensionPixelOffset(v5), 0);
                        v0.setLayoutParams(layoutParams);
                        break;
                    }
                    case 4: {
                        v0 = this.mRightInfoLayoutGroup;
                        if (this.mAppData.getAppSettings().isSingleImageGravityChange()) {
                            layoutParams.setMargins(((int) UIUtils.dp2px(this.context, 10f)),
                                    this.context.getResources().getDimensionPixelOffset(com.ss.android.article.browser.R.dimen.hb), 0, 0);
                        } else {
                            layoutParams.setMargins(0, this.context.getResources().getDimensionPixelOffset(com.ss.android.article.browser.R.dimen.hb),
                                    this.context.getResources().getDimensionPixelOffset(com.ss.android.article.browser.R.dimen.ha), 0);
                        }

                        v0.setLayoutParams(((ViewGroup.LayoutParams) layoutParams));
                        break;
                    }
                    default: {
                        v0 = this.mImage3InfoLayout;
                        break;
                    }
                }

                if (v0 != null) {
                    v0.setVisibility(View.VISIBLE);
                    InfoLayout.Info v1_1 = InfoLayout.Info.acquireInfo();
                    this.b(v1_1);
                    v0.setDislikeOnClickListener(this.popIconClickListener);
                    v0.a(v1_1);
                    ViewGroup.LayoutParams v0_1 = v0.getLayoutParams();
                    if (!this.mAppData.getAppSettings().isFeedCellSpacingChange()) {
                        ((ViewGroup.MarginLayoutParams) v0_1).topMargin = this.context.getResources().getDimensionPixelSize(com.ss.android.article.browser.R.dimen.e7);
                    } else if (this.mAppData.getAppSettings().isMaxCellSpacingChange()) {
                        ((ViewGroup.MarginLayoutParams) v0_1).topMargin = ((int) UIUtils.dp2px(this.context, 5f));
                    } else {
                        ((ViewGroup.MarginLayoutParams) v0_1).topMargin = ((int) UIUtils.dp2px(this.context, 6f));
                    }
                }

                this.a(this.o.appAdTitle, this.o.h);
                this.l();
                if (this.mCellRef != null && this.o != null && this.mActionAdInfoLayout != null) {
                    String v0_2 = this.mCellRef.subTitle;
                    if (!android.support.design.a.isTextEmpty(v0_2) && !android.support.design.a.isTextEmpty(v0_2.trim())) {
                        this.mActionAdInfoLayout.setText(((CharSequence) v0_2));
                    } else {
                        this.mActionAdInfoLayout.setText(this.o.appAdSource);
                    }
                }

                label_81:
                if (this.mAdActionBtnLayout != null && this.o != null && this.mActionAdTv != null) {
                    UIUtils.setVisibility(this.mActionAdIcon, 0);
                    if (!android.support.design.a.isTextEmpty(this.o.btnText)) {
                        this.mActionAdTv.setText(this.o.btnText);
                    } else if (this.o.actionType == 1) {
                        this.mActionAdTv.setText(this.resources.getString(com.ss.android.article.browser.R.string.actionad_action_text));
                    }
                }

                this.a(this.mActionAdInfoLayout, this.o.h);
                UIUtils.setVisibility(this.mLbsAdInfoLayout, v8);
                UIUtils.setVisibility(this.mAppAdInfoLayout, v8);
                UIUtils.setVisibility(this.mActionAdInfoLayout, 0);
                UIUtils.setVisibility(this.mAdActionBtnLayout, 0);
                if (this.mActionAdDivider == null) {
                    return;
                }

                if (this.mActionAdIcon == null) {
                    return;
                }

                if (this.p()) {
                    this.mActionAdDivider.setVisibility(View.VISIBLE);
                    this.mActionAdIcon.setVisibility(v8);
                    return;
                }

                this.mActionAdDivider.setVisibility(v8);
                this.mActionAdIcon.setVisibility(View.VISIBLE);
            }
        }
    }

    protected final void h() {
        super.h();
        if (this.mActionAdInfoLayout != null) {
            this.mActionAdInfoLayout.setTextColor(ContextCompat.getColor(this.context, com.ss.android.article.browser.R.color.ssxinzi3));
        }

        if (this.mActionAdProgress != null) {
            this.mActionAdProgress.setProgressDrawable(this.resources.getDrawable(com.ss.android.article.browser.R.drawable.action_ad_progress_bar_horizontal));
            this.mActionAdProgress.getProgressDrawable().setBounds(this.mActionAdProgress.getProgressDrawable().getBounds());
        }
    }

    protected final void adaptAdActionBtnLayoutNightMode() {
        super.adaptAdActionBtnLayoutNightMode();
        if (this.p()) {
            UIUtils.setBackgroundResource(this.mAdActionBtnLayout, com.ss.android.article.browser.R.color.transparent);
        } else {
            UIUtils.setBackgroundResource(this.mAdActionBtnLayout, com.ss.android.article.browser.R.drawable.ad_action_btn_begin_bg);
        }

        if (this.mActionAdTv != null) {
            if (this.p()) {
                this.mActionAdTv.setTextColor(this.resources.getColorStateList(com.ss.android.article.browser.R.color.xy));
                this.mActionAdTv.setTextSize(17f);
            } else {
                this.mActionAdTv.setTextColor(this.resources.getColor(com.ss.android.article.browser.R.color.ad_action_btn_begin_text_color));
                this.mActionAdTv.setTextSize(12f);
            }
        }

        if (this.mActionAdProgress != null) {
            this.mActionAdProgress.setVisibility(View.INVISIBLE);
        }
    }

    protected final void j() {
        ViewGroup.LayoutParams v0;
        if (this.mRightImageAdImageLayout != null && this.o != null && this.o.imageInfo != null && (this.o.imageInfo.isValid())) {
            if (this.p()) {
                v0 = this.mRightImageAdImageLayout.getLayoutParams();
                v0.width = com.ss.android.article.base.feature.app.a.b.f;
                v0.height = com.ss.android.article.base.feature.app.a.b.g;
            } else {
                v0 = this.mRightImageAdImageLayout.getLayoutParams();
                v0.width = com.ss.android.article.base.feature.app.a.b.h;
                v0.height = com.ss.android.article.base.feature.app.a.b.h * this.o.imageInfo.mHeight / this.o.imageInfo.mWidth;
            }
        }
    }

    public final void onMovedToScrapHeap() {
        super.onMovedToScrapHeap();
        UIUtils.setVisibility(this.mActionAdInfoLayout, 8);
        if (this.mImage3InfoLayout != null) {
            ViewGroup.LayoutParams lp = this.mImage3InfoLayout.getLayoutParams();
            if (!this.mAppData.getAppSettings().isFeedCellSpacingChange()) {
                ((ViewGroup.MarginLayoutParams) lp).bottomMargin = this.context.getResources().getDimensionPixelSize(com.ss.android.article.browser.R.dimen.feed_info_layout_margin_bottom);
                ((ViewGroup.MarginLayoutParams) lp).topMargin = this.context.getResources().getDimensionPixelSize(com.ss.android.article.browser.R.dimen.feed_info_layout_title_gap);
            } else if (this.mAppData.getAppSettings().isMaxCellSpacingChange()) {
                ((ViewGroup.MarginLayoutParams) lp).topMargin = ((int) UIUtils.dp2px(this.context, 5f));
                ((ViewGroup.MarginLayoutParams) lp).bottomMargin = ((int) UIUtils.dp2px(this.context, 6f));
            } else {
                ((ViewGroup.MarginLayoutParams) lp).topMargin = ((int) UIUtils.dp2px(this.context, 6f));
                ((ViewGroup.MarginLayoutParams) lp).bottomMargin = ((int) UIUtils.dp2px(this.context, 7f));
            }
        }
    }

    protected final void l() {
        super.l();
        a(this.mAdActionBtnLayout, this.p);
    }

    protected final void l_() {
        if (this.mLargeImage != null && this.o != null && this.o.imageInfo != null && (this.o.imageInfo.isValid())) {
            b(this.mLargeImage, this.r * this.o.imageInfo.mHeight / this.o.imageInfo.mWidth);
        }
    }

    protected final int m() {
        return this.o != null ? this.o.h : 0;
    }

    protected final String n() {
        String v0 = this.o != null ? this.o.appAdSourceLabel : null;
        return v0;
    }

    protected final int o() {
        return 16;
    }

    private boolean p() {
        boolean v0;
        if (this.o != null) {
            if (this.o.h != 3 && this.o.h != 4) {
                return false;
            }
            v0 = true;
        } else {
            v0 = false;
        }

        return v0;
    }
}

